package com.qfedu.edu.orderservice.slot.impl;

import com.qfedu.edu.constance.RedisConstance;
import com.qfedu.edu.manager.RedisManager;
import com.qfedu.edu.orderservice.slot.generic.GenericSlot;
import org.qfedu.edu.service.IJwtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xiaobobo
 * @title: PassCountSlot
 * @projectName seckill-fy-2401-parent
 * @description: 放行计数的这个Slot
 * 比如：放行了多少人去秒杀这个商品
 * @date 2024/11/11  16:38
 */
@Component
public class PassCountSlot extends GenericSlot {

    @Autowired
    private IJwtService jwtService;

    @Autowired
    private RedisManager redisManager;


    @Override
    public int getOrder() {
        return Integer.MIN_VALUE+3;
    }

    @Override
    public void dealRequest(HttpServletRequest req, HttpServletResponse resp) {
        /**
         * 放行一个人去秒杀商品那么就计数为1
         * 计数在Redis中如何设计呢?
         * buy:count:商品id 数字
         */
        //执行到这里 说明用户可以购买这个商品
        //获取商品id
        String classId = req.getParameter("classId");
        String key=RedisConstance.getBuyCountPrefix()+classId;
        //接下来就可以incr了
        redisManager.incr(key,1);
    }
}
